<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>统计数组中所有的值</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.array-combine.html">« array_combine</a></li>
      <li style="float: right;"><a href="function.array-diff-assoc.html">array_diff_assoc »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.array.html">数组 函数</a></li>
    <li>统计数组中所有的值</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.array-count-values" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_count_values</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_count_values</span> &mdash; <span class="dc-title">统计数组中所有的值</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.array-count-values-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_count_values</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>array_count_values()</strong></span> 返回一个数组：
     数组的键（必须是 <span class="type">int</span> 或 <span class="type">string</span>）是 <code class="parameter">array</code> 里单元的值；
     数组的值是 <code class="parameter">array</code> 单元的值出现的次数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-count-values-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">array</code></dt>

     <dd>

      <p class="para">
       统计这个数组的值
      </p>
     </dd>

    

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-count-values-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    返回一个关联数组，用 <code class="parameter">array</code>
     数组中的值作为键名，该值在数组中出现的次数作为值。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.array-count-values-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   对数组里面的每个不是 <span class="type">string</span> 或 <span class="type">int</span> 类型的元素抛出一个警告错误（<strong><code>E_WARNING</code></strong>）。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-count-values-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4900">
    <p><strong>示例 #1 <span class="function"><strong>array_count_values()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"world"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">array_count_values</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [1] =&gt; 2
    [hello] =&gt; 2
    [world] =&gt; 1
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-count-values-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.count.html" class="function" rel="rdfs-seeAlso">count()</a> - 统计数组、Countable 对象中所有元素的数量</span></li>
    <li class="member"><span class="function"><a href="function.array-unique.html" class="function" rel="rdfs-seeAlso">array_unique()</a> - 移除数组中重复的值</span></li>
    <li class="member"><span class="function"><a href="function.array-values.html" class="function" rel="rdfs-seeAlso">array_values()</a> - 返回数组中所有的值</span></li>
    <li class="member"><span class="function"><a href="function.count-chars.html" class="function" rel="rdfs-seeAlso">count_chars()</a> - 返回字符串所用字符的信息</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>